﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEngine;

public class StreamingAsset
{
    [CompilerGenerated]
    private static Func<string, bool> <>f__am$cache7;
    [CompilerGenerated]
    private static Func<string, StreamingAsset> <>f__am$cache8;
    [CompilerGenerated]
    private static Func<StreamingAsset, string> <>f__am$cache9;
    [CompilerGenerated]
    private static Func<StreamingAsset, StreamingAsset> <>f__am$cacheA;
    public static string[] audioExtensions = new string[] { ".wav", ".mp3" };
    private static Dictionary<string, StreamingAsset> m_assetLookup;
    private static StreamingAsset[] m_assets;
    public static string[] textExtensions = new string[] { ".txt", ".csv", ".lua", ".xml", ".json", ".prefab" };
    public static string[] textureExtensions = new string[] { ".png", ".jpg" };

    public StreamingAsset(string fullPath)
    {
        fullPath = fullPath.Replace(@"\", "/");
        this.fullPath = fullPath;
        this.name = fullPath.Replace(Application.streamingAssetsPath + "/", string.Empty);
    }

    public static void ClearCaches()
    {
        m_assets = null;
        m_assetLookup = null;
    }

    public static bool Contains(string assetName)
    {
        return assetLookup.ContainsKey(assetName);
    }

    public static StreamingAsset Get(string assetName)
    {
        if (assetName != null)
        {
            StreamingAsset asset;
            assetName = assetName.Replace(@"\", "/").Replace(Application.streamingAssetsPath + "/", string.Empty);
            if (assetLookup.TryGetValue(assetName, out asset))
            {
                return asset;
            }
        }
        return null;
    }

    public static IEnumerable<StreamingAsset> GetAll(string folderPath, params string[] extensions)
    {
        <GetAll>c__AnonStorey95 storey = new <GetAll>c__AnonStorey95 {
            folderPath = folderPath,
            extensions = extensions
        };
        return assets.Where<StreamingAsset>(new Func<StreamingAsset, bool>(storey.<>m__1A9));
    }

    public static AudioClip LoadAudio(string assetName)
    {
        StreamingAsset asset = Get(assetName);
        return ((asset == null) ? null : asset.audioClip);
    }

    public static string LoadText(string assetName)
    {
        StreamingAsset asset = Get(assetName);
        return ((asset == null) ? null : asset.text);
    }

    public static Texture2D LoadTexture(string assetName)
    {
        StreamingAsset asset = Get(assetName);
        return ((asset == null) ? null : asset.texture);
    }

    private static Dictionary<string, StreamingAsset> assetLookup
    {
        get
        {
            if (m_assetLookup == null)
            {
                if (<>f__am$cache9 == null)
                {
                    <>f__am$cache9 = x => x.name;
                }
                if (<>f__am$cacheA == null)
                {
                    <>f__am$cacheA = x => x;
                }
                m_assetLookup = assets.ToDictionary<StreamingAsset, string, StreamingAsset>(<>f__am$cache9, <>f__am$cacheA, StringComparer.CurrentCultureIgnoreCase);
            }
            return m_assetLookup;
        }
    }

    private static StreamingAsset[] assets
    {
        get
        {
            if (m_assets == null)
            {
                if (<>f__am$cache7 == null)
                {
                    <>f__am$cache7 = x => !StreamingAssetUtility.IsAnyExtension(x, new string[] { ".meta" });
                }
                if (<>f__am$cache8 == null)
                {
                    <>f__am$cache8 = x => new StreamingAsset(x);
                }
                m_assets = Directory.GetFiles(Application.streamingAssetsPath, "*.*", SearchOption.AllDirectories).Where<string>(<>f__am$cache7).Select<string, StreamingAsset>(<>f__am$cache8).ToArray<StreamingAsset>();
            }
            return m_assets;
        }
    }

    public AudioClip audioClip
    {
        get
        {
            return StreamingAssetUtility.Load(this.fullPath).audioClip;
        }
    }

    public string extension
    {
        get
        {
            return Path.GetExtension(this.fullPath);
        }
    }

    public string folderName
    {
        get
        {
            return Path.GetDirectoryName(this.fullPath);
        }
    }

    public string folderShortName
    {
        get
        {
            char[] separator = new char[] { '/' };
            return this.folderName.Split(separator).LastOrDefault<string>();
        }
    }

    public string fullPath { get; private set; }

    public string fullPathWithoutExtension
    {
        get
        {
            return this.fullPath.Replace(this.extension, string.Empty);
        }
    }

    public string name { get; private set; }

    public string text
    {
        get
        {
            return StreamingAssetUtility.Load(this.fullPath).text;
        }
    }

    public Texture2D texture
    {
        get
        {
            return StreamingAssetUtility.Load(this.fullPath).texture;
        }
    }

    [CompilerGenerated]
    private sealed class <GetAll>c__AnonStorey95
    {
        internal string[] extensions;
        internal string folderPath;

        internal bool <>m__1A9(StreamingAsset x)
        {
            return (x.fullPath.StartsWith(this.folderPath) && StreamingAssetUtility.IsAnyExtension(x.fullPath, this.extensions));
        }
    }
}

